package com.jthink.blog.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jthink.cms.constants.CommentState;
import com.jthink.cms.entity.PostComment;
import com.jthink.cms.service.PostCommentService;
import com.jthink.cms.service.PostService;
import com.jthink.member.entity.Member;
import com.jthink.permission.service.UserService;
import com.jthink.security.util.StpMemberUtil;
import com.jthink.shop.service.MemberService;
import com.jthink.utils.ResponseBo;

import cn.dev33.satoken.annotation.SaCheckLogin;

@Controller
public class BlogCommentController {
	@Autowired
	private PostService postService;
	@Autowired
	private PostCommentService postCommentService;
	@Autowired
	private UserService userService;
	@Autowired
	private MemberService memberService;
	@SaCheckLogin
	@RequestMapping("/member/post/sendComment")
	@ResponseBody
	public ResponseBo sendComment(PostComment comment ) {
		comment.setCreateTime(new Date());
		comment.setCommentApproved(CommentState.AUDIT);
		Integer memberId=StpMemberUtil.getLoginIdAsInt();
		Member member= memberService.selectByKey(memberId);
		comment.setCommentAuthor(member.getNickname());
		comment.setUserId(memberId);
				// 审核中
		comment.setCommentApproved(CommentState.AUDIT);
		postCommentService.save(comment);
		return ResponseBo.ok();
	}
}
